<?php

namespace App\Http\Controllers;

use App\Http\Requests\ContentArticleAdd;
use App\Models\ContentArticle;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ContentArticleController extends BaseController
{
    public function add(ContentArticleAdd $request)
    {
        $ca = new ContentArticle();
        $ca->user_id = $this->userId;
        $ca->title = $request->input('title');
        $ca->cover = $request->input('cover');
        $ca->content = $request->input('content');
        $ca->album_id = $request->input('album_id');
        $ca->group_id = $request->input('group_id');
        $ca->status = $request->input('type');
        $ca->tag = $request->input('tag', '');

        DB::beginTransaction();

        if ($ca->save()) {
            if ($this->contentPP()) {
                DB::commit();
                return $this->jsonResultOk();
            }

        }

        DB::rollBack();
        return $this->jsonResultFail();
    }

}
